package pa1.helloworld_example;

import java.rmi.Naming;
import java.rmi.registry.Registry;

public class HelloClient
{
    public static void main(String args[])
    {
        String host = "localhost";
        String port = Integer.toString(Registry.REGISTRY_PORT);

        if (args.length > 0) {
            host = args[0];
            if (args.length > 1) {
                port = args[1];
            }
        }
        if (args.length > 2) {
            System.out.println(
                "Usage: java helloworld.HelloClient [host [port]]");
            System.exit(1);
        }

        try {
	    System.out.println("Looking up Hello at " + host + ":" + port);
            Hello obj = (Hello) Naming.lookup("//" + host + ":" + port + "/" + Hello.SERVICENAME);
            String message = obj.sayHello();
            System.out.println(message);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
